{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑消息</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">
                        <input type="hidden" name="n_id" value="{$info.n_id}">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">标题：</label>
                            <div class="layui-input-block">
                                <input type="text" value="{$info.n_title}" name="n_title" lay-verify="required" placeholder="标题" class="layui-input ">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 wbwb {if $info.n_type==2}hidden{/if}">
                            <label class="layui-form-label">内容：</label>
                            <div class="layui-input-block">
                                <textarea name="n_content" id="n_content" class="layui-input " style="height:80px">{$info.n_content}</textarea>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">选择类型：</label>
                            <div class="layui-input-block">
                                <select name="n_type" id="n_type" lay-filter="role">
                                    <option value="1" {$info.n_type==1?'selected':''}>文本消息</option>
                                    <option value="2" {$info.n_type==2?'selected':''}>图片消息</option>
                                    <option value="3" {$info.n_type==3?'selected':''}>图文消息</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 sltslt {if $info.n_type==1}hidden{/if}">
                            <label class="layui-form-label">缩略图：</label>
                            <input type="hidden" name="n_image" id="lay-img" lay-verify="image" value="{$info.n_image}">
                            <div class="layui-input-block">
                                <div id="lay-upload">上传图片</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="lay-list">
                                        <img class="layui-append-img" src="{$info.n_image}" onerror="this.src='/static/admin/images/no_img.jpg'">
                                    </div>
                                </blockquote>
                            </div>
                        </div>


                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""});
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;

        form.on('submit(component-form-element)', function (data) {
            var ji = $('#n_type').val();
            var nr = $('#n_content').val().trim();
            var img = $('#lay-img').val().trim();
            if(ji == 1){
                if(nr == ''){
                    alert('请填写内容');
                    return false;
                }
            }else if(ji == 2){
                if(img == ''){
                    alert('请上传图片');
                    return false;
                }
            }else{
                if(nr == '' || img == ''){
                    alert('有未填项');
                    return false;
                }else{

                }
            }
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('noticeEdit')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('Notice/index')}")
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
        form.on('select(role)', function(data){
            wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""});
            if(data.value == 1){
                $(".sltslt").addClass('hidden');
            }else {
                $(".sltslt").removeClass('hidden');
            }
            if(data.value == 2){
                $(".wbwb").addClass('hidden');
            }else {
                $(".wbwb").removeClass('hidden');
            }
        });
    });
</script>
</body>
</html>
